package com.gzkit.demo.service.sms;

import com.gzkit.baseframework.core.sms.AbstractSmsValidationService;
import com.gzkit.baseframework.sys.user.service.SysUserBaseService;
import com.gzkit.baseframework.sys.user.vo.SysUserBaseVO;
import org.apache.commons.lang3.StringUtils;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

@Service
public class MockSmsValidationService extends AbstractSmsValidationService {

    private final SysUserBaseService userService;

    public MockSmsValidationService(RedisTemplate redisTemplate, SysUserBaseService userService) {
        super(redisTemplate);
        this.userService = userService;
    }

    @Override
    protected String send(final String mobile, final int expiredTimeInMinutes) {
        return "100000";
    }

    @Override
    public boolean verifyCode(String username, String code) {
        SysUserBaseVO vo = new SysUserBaseVO();
        vo.setUsername(username);

        SysUserBaseVO user = userService.getOne(vo);
        if (user == null || StringUtils.isEmpty(user.getPhone())) {
            return false;
        }

        return super.verifyCode(user.getPhone(), code);
    }
}